/**
 * 作者：陈文斌 on 2019/1/8.
 * 邮箱：chen_wennbin@163.com
 * 版本：v1.0
 */

import 'package:flutter/material.dart';
import 'package:crm/constant/constant.dart';
import 'package:crm/model/main_scoped_model.dart';
import 'package:crm/component/ClientManager/AddClient/add_client_prompt_bar_section.dart';
import 'package:crm/component/ClientManager/AddClient/add_client_list_section.dart';
import 'package:crm/view/AppBar/custom_app_bar.dart';

const String Title = '添加客户';

class AddClientPage extends StatefulWidget {
  /// 客户类型，0为正式，1为潜在，默认为正式客户(customerType = 0)
  final int clientType;

  @override
  AddClientPage({
    Key key,
    this.clientType = 0,
  }) : super(key: key);

  State<StatefulWidget> createState() => _AddClientPageState();
}

class _AddClientPageState extends State<AddClientPage> {
  @override
  void initState() {
    /// 添加新客户，初始化全局状态
    MainModel clientManagerSM = MainModel().of(context);
    clientManagerSM.initClientInfo();
    clientManagerSM.initContactInfoList();
    clientManagerSM.initIndustryCategory();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      backgroundColor: AppColors.PageBackgroundColor,
      appBar: CustomAppBar(
        title: widget.clientType == 0 ? Title : '添加潜在客户',
      ),
      body: GestureDetector(
        onTap: () {
          FocusScope.of(context).requestFocus(FocusNode());
        },
        child: Column(
          children: <Widget>[
            AddClientPromptBarSection(
              clientType: widget.clientType,
            ),
            AddClientListSection(
              clientType: widget.clientType,
            ),
          ],
        ),
      ),
    );
  }
}
